using System;

namespace XEAS.Framework.Data
{
    public sealed class DataAccessManager
    {
        public static iDataAccessLayer CreateAccessLayer(eDataAccessLayerType dataAccessLayerType,
                                                         string connectionString)
        {
            switch (dataAccessLayerType)
            {
                case eDataAccessLayerType.OleDb:
                    return new OleDbAccessLayer(connectionString);

                case eDataAccessLayerType.Odbc:
                    return new OdbcAccessLayer(connectionString);

                case eDataAccessLayerType.Oracle:
                    return new OracleAccessLayer(connectionString);

                case eDataAccessLayerType.VistaDb:
                    throw new Exception("Current version of G&L iCore does not support VistaDb");

                case eDataAccessLayerType.SqlLite:
                    return new SQLiteAccessLayer(connectionString);
            }
            return new SqlAccessLayer(connectionString);
        }

        public static iDataAccessLayer CreateAccessLayer(eDataAccessLayerType dataAccessLayerType,
                                                         string connectionString, bool autoCloseConnection)
        {
            switch (dataAccessLayerType)
            {
                case eDataAccessLayerType.OleDb:
                    return new OleDbAccessLayer(connectionString, autoCloseConnection);

                case eDataAccessLayerType.Odbc:
                    return new OdbcAccessLayer(connectionString, autoCloseConnection);

                case eDataAccessLayerType.Oracle:
                    return new OracleAccessLayer(connectionString, autoCloseConnection);

                case eDataAccessLayerType.VistaDb:
                    throw new Exception("Current version of G&L iCore does not support VistaDb");

                case eDataAccessLayerType.SqlLite:
                    return new SQLiteAccessLayer(connectionString, autoCloseConnection);
            }
            return new SqlAccessLayer(connectionString, autoCloseConnection);
        }

        public static iDataAccessLayer CreateAccessLayer(eDataAccessLayerType dataAccessLayerType,
                                                         string connectionString, bool autoCloseConnection,
                                                         bool useCommonConnection)
        {
            switch (dataAccessLayerType)
            {
                case eDataAccessLayerType.OleDb:
                    return new OleDbAccessLayer(connectionString, autoCloseConnection, useCommonConnection);

                case eDataAccessLayerType.Odbc:
                    return new OdbcAccessLayer(connectionString, autoCloseConnection, useCommonConnection);

                case eDataAccessLayerType.Oracle:
                    return new OracleAccessLayer(connectionString, autoCloseConnection, useCommonConnection);

                case eDataAccessLayerType.VistaDb:
                    throw new Exception("Current version of G&L iCore does not support VistaDb");

                case eDataAccessLayerType.SqlLite:
                    return new SQLiteAccessLayer(connectionString, autoCloseConnection, useCommonConnection);
            }
            return new SqlAccessLayer(connectionString, autoCloseConnection, useCommonConnection);
        }
    }
}